//
//  LocationModel.m
//  BrotherMovProject
//
//  Created by zhibao on 2022/1/19.
//

#import "LocationModel.h"
@interface LocationModel(){
    
}
@end
@implementation LocationModel

- (instancetype)init{
    self = [super init];
    if (self) {
        NSString *tempStr = LocalizedString(@"请输入");
        self.formattedAddress = LocalizedString(@"未知");
        self.country = LocalizedString(@"未知");
        self.province = LocalizedString(@"未知");
        self.city = LocalizedString(@"未知");
        self.district = LocalizedString(@"未知");
        self.citycode = LocalizedString(@"未知");
        self.adcode = LocalizedString(@"未知");
        self.street = LocalizedString(@"未知");
        self.number = LocalizedString(@"未知");
        self.POIName = LocalizedString(@"未知");
        self.AOIName = LocalizedString(@"未知");
        self.lon = LocalizedString(@"未知");
        self.lat = LocalizedString(@"未知");
        self.weather = LocalizedString(@"未知");
        self.temperature = LocalizedString(@"未知");
        self.windDirection = LocalizedString(@"未知");
        self.windPower = LocalizedString(@"未知");
        self.humidity = LocalizedString(@"未知");
        self.date = LocalizedString(@"未知");
        self.week = LocalizedString(@"未知");
        self.name = LocalizedString(@"未知");
        self.addInfo = LocalizedString(@"未知");
        self.tianqi = LocalizedString(@"未知");
        self.jw = LocalizedString(@"未知");
        self.sjdkbz = LocalizedString(@"暂无");
        self.sjdkdd = LocalizedString(@"暂无");
        self.kqdlbz = LocalizedString(@"暂无");
        self.kqdkdd = LocalizedString(@"暂未定位");
        
        self.wybz = LocalizedString(@"暂无");
        self.wydd = LocalizedString(@"暂未定位");
       
        self.gcmz = tempStr;
        self.quyu = tempStr;
        self.sgnr = tempStr;
        self.sgfzr = tempStr;
        self.jlfzr = tempStr;
        self.jsdw = tempStr;
        self.jldw = tempStr;
        self.sgdw = tempStr;
        self.sjdw = tempStr;
        self.ktdw = tempStr;
        
        self.zqry = tempStr;
        self.xlqy = tempStr;
        self.xljg = tempStr;
        self.tfsj = tempStr;
        self.xlbz = LocalizedString(@"暂无");
        self.xldd = LocalizedString(@"暂未定位");
        
        self.psr = tempStr;
        self.psnr = tempStr;
        self.sjr = tempStr;
        self.sjrdh = tempStr;
        self.jjr = tempStr;
        self.jjrdh = tempStr;
        self.kdgs = tempStr;
        self.kdbz = LocalizedString(@"暂无");
        self.kddd = LocalizedString(@"暂未定位");
        
        self.xjry = tempStr;
        self.xjnr = tempStr;
        self.rcbz = LocalizedString(@"暂无");
        self.rcdd = LocalizedString(@"暂未定位");
        
        self.jzry = tempStr;
        self.gznr = tempStr;
        self.jzbz = LocalizedString(@"暂无");
        self.jzdd = LocalizedString(@"暂未定位");
        
        self.hymc = tempStr;
        self.hyrs = tempStr;
        self.hynr = tempStr;
        self.hydd = tempStr;
        self.zcr = tempStr;
        self.yhry = tempStr;
        self.hyjybz = LocalizedString(@"暂无");
        
        self.dkr = tempStr;
        self.khmc = tempStr;
        self.fwyzbz = LocalizedString(@"暂无");
        self.fwdd = LocalizedString(@"暂未定位");
        
        self.jdr = tempStr;
        self.gcxm = tempStr;
        self.rwkhmc = tempStr;
        self.lxfs = tempStr;
        self.rwdd = tempStr;
        self.rwbz = LocalizedString(@"暂无");
        
        self.wpry = tempStr;
        self.wpdd = tempStr;
        self.wpnr = tempStr;
        self.wpbz = LocalizedString(@"暂无");
        
        self.gzxm = tempStr;
        self.hgxm = tempStr;
        self.galxfs = tempStr;
        self.gabz = LocalizedString(@"暂无");
        self.gadd = LocalizedString(@"暂未定位");
        
        self.jdmc = tempStr;
        self.lyry = tempStr;
        self.lyrs = tempStr;
        self.lybz = LocalizedString(@"暂无");
        self.lydd = LocalizedString(@"暂未定位");
    }
    return self;
}
-(id)copyWithZone:(NSZone *)zone
{
    NSLog(@"自定义对象拷贝");

    //allocWithZone: 开辟zone大小的空间
    LocationModel *xiaoM = [LocationModel allocWithZone:zone];
    xiaoM.formattedAddress = self.formattedAddress;
    xiaoM.country = self.country;
    xiaoM.province = self.province;
    xiaoM.city = self.city;
    xiaoM.district = self.district;
    xiaoM.citycode = self.citycode;
    xiaoM.adcode = self.adcode;
    xiaoM.street = self.street;
    xiaoM.areaCode = self.areaCode;
    xiaoM.number = self.number;
    xiaoM.POIName = self.POIName;
    xiaoM.AOIName = self.AOIName;
    xiaoM.lon = self.lon;
    xiaoM.lat = self.lat;
    xiaoM.weather = self.weather;
    xiaoM.temperature = self.temperature;
    xiaoM.windDirection = self.windDirection;
    xiaoM.windPower = self.windPower;
    xiaoM.humidity = self.humidity;
    xiaoM.date = self.date;
    xiaoM.week = self.week;
    xiaoM.name = self.name;
    xiaoM.addInfo = self.addInfo;
    xiaoM.tianqi = self.tianqi;
    xiaoM.jw = self.jw;

    return xiaoM;
}


-(id)mutableCopyWithZone:(NSZone *)zone
{
    NSLog(@"自定义对象的mutable拷贝");

    LocationModel *xiaoM = [LocationModel allocWithZone:zone];
    xiaoM.formattedAddress = self.formattedAddress;
    xiaoM.country = self.country;
    xiaoM.province = self.province;
    xiaoM.city = self.city;
    xiaoM.district = self.district;
    xiaoM.citycode = self.citycode;
    xiaoM.adcode = self.adcode;
    xiaoM.street = self.street;
    xiaoM.areaCode = self.areaCode;
    xiaoM.number = self.number;
    xiaoM.POIName = self.POIName;
    xiaoM.AOIName = self.AOIName;
    xiaoM.lon = self.lon;
    xiaoM.lat = self.lat;
    xiaoM.weather = self.weather;
    xiaoM.temperature = self.temperature;
    xiaoM.windDirection = self.windDirection;
    xiaoM.windPower = self.windPower;
    xiaoM.humidity = self.humidity;
    xiaoM.date = self.date;
    xiaoM.week = self.week;
    xiaoM.name = self.name;
    xiaoM.addInfo = self.addInfo;
    xiaoM.tianqi = self.tianqi;
    xiaoM.jw = self.jw;
    return xiaoM;
}
//模型转字典
- (NSDictionary *)dicFromObject:(NSObject *)object {
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    unsigned int count;
    objc_property_t *propertyList = class_copyPropertyList([object class], &count);
    
    for (int i = 0; i < count; i++) {
        objc_property_t property = propertyList[i];
        const char *cName = property_getName(property);
        NSString *name = [NSString stringWithUTF8String:cName];
        NSObject *value = [object valueForKey:name];//valueForKey返回的数字和字符串都是对象
        
        if ([value isKindOfClass:[NSString class]] || [value isKindOfClass:[NSNumber class]]) {
            //string , bool, int ,NSinteger
            [dic setObject:value forKey:name];
            
        } else if ([value isKindOfClass:[NSArray class]]) {
            //数组或字典
            [dic setObject:[self arrayWithObject:value] forKey:name];
        } else if ([value isKindOfClass:[NSDictionary class]]) {
            //数组或字典
            [dic setObject:[self dicWithObject:value] forKey:name];
        } else if (value == nil) {
            //null
            //[dic setObject:[NSNull null] forKey:name];//这行可以注释掉?????
        } else {
            //model
            [dic setObject:[self dicFromObject:value] forKey:name];
        }
    }
    
    return [dic copy];
}

//转数组
- (NSArray *)arrayWithObject:(id)object {
    //数组
    NSMutableArray *array = [NSMutableArray array];
    NSArray *originArr = (NSArray *)object;
    if ([originArr isKindOfClass:[NSArray class]]) {
        for (NSObject *object in originArr) {
            if ([object isKindOfClass:[NSString class]]||[object isKindOfClass:[NSNumber class]]) {
                //string , bool, int ,NSinteger
                [array addObject:object];
            } else if ([object isKindOfClass:[NSArray class]]) {
                //数组或字典
                [array addObject:[self arrayWithObject:object]];
            } else if ([object isKindOfClass:[NSDictionary class]]) {
                //数组或字典
                [array addObject:[self dicWithObject:object]];
            } else {
                //model
                [array addObject:[self dicFromObject:object]];
            }
        }
        return [array copy];
    }
    return array.copy;
}

//转字典类型
- (NSDictionary *)dicWithObject:(id)object {
    //字典
    NSDictionary *originDic = (NSDictionary *)object;
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    if ([object isKindOfClass:[NSDictionary class]]) {
        for (NSString *key in originDic.allKeys) {
            id object = [originDic objectForKey:key];
            if ([object isKindOfClass:[NSString class]]||[object isKindOfClass:[NSNumber class]]) {
                //string , bool, int ,NSinteger
                [dic setObject:object forKey:key];
            } else if ([object isKindOfClass:[NSArray class]]) {
                //数组或字典
                [dic setObject:[self arrayWithObject:object] forKey:key];
            } else if ([object isKindOfClass:[NSDictionary class]]) {
                //数组或字典
                [dic setObject:[self dicWithObject:object] forKey:key];
            } else {
                //model
                [dic setObject:[self dicFromObject:object] forKey:key];
            }
        }
        return [dic copy];
    }
    return dic.copy;
}
@end
